from reptile.workproject import WorkProject
from pyquery import PyQuery as pq


class ProxyIp3366(WorkProject):

	def work(self):
		super().work()
		for page_number in range(1, 4):
			page = self.scraper.send_request(
				url = "https://proxy.ip3366.net/free/?action=china&page={}".format(page_number))
			if page is None:
				continue
			for tr in pq(page)("table.table-bordered tr").items():
				data = [td.text() for td in tr.find("td").items()]
				if len(data) > 0 and data[0] != "":
					self.data.append(
						{"protocol": data[3].split(",")[0].lower(), "ip_port": "{}:{}".format(data[0], data[1]),
						 "country": data[4],
						 "anonymity": data[2] == "高匿"})
